<template>
    <a-modal
        title="台账列表"
        :visible="visible"
        @cancel="cancel"
        @ok="ok"
        :confirm-loading="loading"
        class="normal-modal"
    >
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card :bordered="false">
            <b-table
                ref="table"
                :columns="columns"
                :request="loadData"
                :selectConfig="{use: true, type: 'radio',rowKey: 'id' }"
                @row-click="rowClick"
            >
                <span slot="index" slot-scope="text, record, index">{{ index + 1 }}</span>
                <template slot="assetCode" slot-scope="text, record, index">
                    <span v-if="text">{{ text }}</span>
                    <span v-else style="color: red;">未填写</span>
                </template>
                <template slot="auditStatusStr" slot-scope="text, record, index">
                    <list-status :status="record.auditStatus" :text="text"></list-status>
                </template>
            </b-table>
        </a-card>
    </a-modal>
</template>

<script>
import assetApi from '@/api/office/asset'
import SelectPerson from '@/components/Select/SelectPerson'

export default {
    name: 'assetList',
    components: {
        SelectPerson,
    },
    props: {
        visible: {
            type: Boolean,
            default: false
        }
    },
    data() {
        return {
            loading: false,
            row: null,
            columns: [
                {
                    title: '序号',
                    dataIndex: 'index',
                    width: 70,
                    scopedSlots: { customRender: 'index' }
                },
                {
                    title: '资产编号',
                    dataIndex: 'assetCode',
                    scopedSlots: { customRender: 'assetCode' },
                    width: 150
                },
                {
                    title: '资产名称',
                    dataIndex: 'assetName',
                    width: 120
                },
                {
                    title: '资产类别',
                    dataIndex: 'assetSpeciesStr',
                    width: 150
                },
                {
                    title: '状态',
                    dataIndex: 'statusStr',
                    width: 150
                }

            ],
            searchArr: [
                {
                    name: '资产编号',
                    value: 'assetCode',
                    type: 'input'
                },
                {
                    name: '资产名称',
                    value: 'assetName',
                    type: 'input'
                }
            ],
            loadData: (params) => {
                return assetApi.getPageParameterTran(Object.assign(params,
                    { query: Object.assign(this.queryParam,{parameterStatus:3}) }))
            },
            queryParam: {}

        }
    },
    created() {
    },
    methods: {
        cancel() {
            this.row = null
            this.$emit('update:visible', false)
        },
        rowClick(e, row) {
            this.row = row
        },
        ok() {
            if (this.row === null) return this.$noticeWarning('请选择数据')
            this.$emit('ok', this.row)
            this.cancel()
        },
        search(val) {
            this.queryParam = val || {}
            this.$refs.table.getData(null, true)
        }
    }
}
</script>
